from bokeh.plotting import figure, show
from bokeh.models import HoverTool
from bokeh.layouts import gridplot

# https://docs.bokeh.org/en/latest/docs/user_guide/basic/scatters.html

# https://blog.csdn.net/Rocky006/article/details/135314421

def t1_zhexian_graph():
    # 创建一个输出HTML文件
    #output_file("simple_line_chart.html")
    
    # 创建一个图表对象
    p = figure(title="Simple Line Chart", x_axis_label="X-axis", y_axis_label="Y-axis")
    
    # 添加数据点
    x = [1, 2, 3, 4, 5]
    y = [6, 7, 2, 4, 5]
    
    # 绘制折线
    p.line(x, y, line_width=2)
    
    # 显示图表
    show(p)

def t0():
    p = figure(width=1000, height=400)

    # add a circle renderer with a size, color, and alpha
    p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)

    # show the results
    show(p)

def t2_show_xy_when_hover():
    # 创建一个图表对象
    p = figure(title="Interactive Line Chart", x_axis_label="X-axis", y_axis_label="Y-axis")
    
    # 添加数据点
    x = [1, 2, 3, 4, 5]
    y = [6, 7, 2, 4, 5]
    
    # 绘制折线
    line = p.line(x, y, line_width=2)
    
    # 添加悬停工具
    hover = HoverTool()
    hover.tooltips = [("X", "@x"), ("Y", "@y")]
    p.add_tools(hover)
    
    # 显示图表
    show(p)

def t3_multiple():
    # 创建多个图表对象
    p1 = figure(title="Subplot 1")
    p2 = figure(title="Subplot 2")
    p3 = figure(title="Subplot 3")
    p4 = figure(title="Subplot 4")
    
    # 添加数据点
    x = [1, 2, 3, 4, 5]
    y1 = [6, 7, 2, 4, 5]
    y2 = [5, 4, 3, 2, 1]
    y3 = [1, 2, 1, 2, 1]
    y4 = [3, 2, 4, 1, 5]
    
    # 绘制子图表
    p1.line(x, y1)
    p2.line(x, y2)
    p3.line(x, y3)
    p4.line(x, y4)
    
    # 创建一个子图表布局
    layout = gridplot([[p1, p2], [p3, p4]])
    
    # 显示图表
    show(layout)

#t1_zhexian_graph()
#t2_show_xy_when_hover()
t3_multiple()